package com.hzx.service.impl;

import java.util.List;
import java.util.Set;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hzx.dao.DeptDao;
import com.hzx.dao.EmpDao;
import com.hzx.entity.Dept;
import com.hzx.entity.Emp;
import com.hzx.entity.PageBean;
import com.hzx.service.EmpService;

@Service
@Transactional
public class EmpServiceImpl implements EmpService {
	@Autowired
	private EmpDao empDao;
	@Autowired
	private DeptDao deptDao;

	@Override
	public void save(Emp model) {
		empDao.save(model);
	}

	@Override
	public void pageQuery(PageBean pageBean) {
		empDao.pageQuery(pageBean);
	}

	@Override
	public void deleteEmp(Integer eid) {
		Emp emp = empDao.findById(eid);
		emp.setEis(0);
		emp.setDept(null);
		empDao.update(emp);
	}

	@Override
	public Emp findByid(Integer eid) {
		return empDao.findById(eid);
	}

	@Override
	public void restoreEmp(Emp model) {
		Emp emp = empDao.findById(model.getEid());
		
		Dept dept = deptDao.findById(model.getDept().getDid());
		
		emp.setDept(dept);
		emp.setEis(1);
		empDao.update(emp);
	}

	@Override
	public void saveOrupdate(Emp model) {
		empDao.saveOrupdate(model);
	}

	@Override
	public List<Emp> findAll() {
		return empDao.getAll();
	}
}
